function visualiseGMMBayes(mix, data, dims, colour, level)

% VISUALISEGMM visualise and a gaussian mixture and the training data
% 
% visualiseGMM(clusters, data, colour, dims, useSeparateColour, clusterIndices)
% 
% clusters, gaussian mixture
% data, data points to be labelled by components of clusters (optional)
% dims, the indices of the two dimensions that are to be visualised, default is [1 2], (optional)
% colour, default colour of clusters (optional)
% cluster_indices, the clusters that are to be visualised, (optional)
% 
% Shaobo Hou

if nargin < 5
    level = 1;
end
if (nargin < 3) || (length(dims) < 2)
    dims = [1 2];
end
if nargin < 2
    data = [];
end

if ~isfield(mix, 'colours')
    mix.colours = rand(mix.ncentres, 3);
end

L = [];
if(numel(data.Y) ~= 0)
    post = gmmpostBayes(mix, data);
    [ignored L] = max(post, [], 2);
end

for i = 1:mix.ncentres;
    cluster_points = data.Y(L == i, :);

    if(numel(cluster_points) ~= 0)
        plot(cluster_points(:, dims(1)), cluster_points(:, dims(2)), '.', 'Color', mix.colours(i, :), 'MarkerSize', 5);
    end
    hold on
    plot(mix.centres(i, dims(1)), mix.centres(i, dims(2)), '+', 'Color', mix.colours(i, :), 'MarkerSize', 20);

    if (nargin < 4) || (length(colour) < 3)
        cluster_colour = mix.colours(i, :);
    else
        cluster_colour = colour;
    end

    elipsnorm(mix.centres(i, dims), mix.covars(dims, dims, i), level, cluster_colour);
end
